<template>
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>
    <a-card>
      <div class="table-operator">
        <a-button v-btnPermission="'hse_011_add_01'" type="primary" icon="plus" @click="edit({}, 1)" v-if="hideBuquBtn()">新增会议
        </a-button>
      </div>
      <list-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <div slot="sort" slot-scope="text, record, index">{{ index + 1 }}</div>
        <div slot="operation" slot-scope="text, record">
          <MoreButton>
            <a @click="look(record)" v-btnPermission="'hse_011_loo_02'">查看会议</a>
            <a @click="edit(record, 2)" v-if="record.status === 20 && $isMe(record.creatorId) &&hideBuquBtn()"
                  v-btnPermission="'hse_011_edi_02'"
            >编辑</a>
            <a @click="handleUpdate('del', record)" v-btnPermission="'hse_011_edi_02'" v-if="hideBuquBtn()">删除</a>
          </MoreButton>
        </div>
        <div slot="commentedPlan" slot-scope="text, record">{{ record.meetingExtraVO.commentedPlan }}</div>
        <div slot="professionComName" slot-scope="text, record">{{ record.meetingExtraVO.professionComName }}</div>
        <div slot="avgScore" slot-scope="text, record">{{ record.meetingExtraVO.avgScore }}</div>
        <div slot="status" slot-scope="text, record">
          <list-status :status="record.status" conversion="en" :text="text"></list-status>
        </div>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import { STable } from '@/components'
import listStatus from '@/components/list_status/meeting_status'
import { getMeetingList, startMeeting, getSearchList, deleteById } from '@/api/office/conference'
import meetingTypeApi from '@/api/safetySupervision/base/meetingType.js'

const columns = [
  {
    title: '序号',
    dataIndex: 'sort',
    width:80,
    scopedSlots: { customRender: 'sort' }
  },
  {
    title: '会议名称',
    dataIndex: 'meetingName',
    width:150,
  },
  {
    title: '会议类型',
    dataIndex: 'meetingKeyName',
    width:100,
  },
  {
    title: '所属分公司',
    dataIndex: 'branchComName',
    width:180,
  },
  {
    title: '所属项目',
    dataIndex: 'projectName',
    width:180,
  },
  {
    title: '召开时间',
    dataIndex: 'startTime',
    width:150,
  },
  {
    title: '参会人数',
    dataIndex: 'meetingCount',
    width:80,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width:80,
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: 150,
    scopedSlots: { customRender: 'operation' }
  }
]
const searchArr = [
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchComId',
  //   type: SelectSubCompany
  // },
  {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchComId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  {
    name: '会议名称',
    value: 'meetingName',
    type: 'input'
  },
  {
    name: '会议类型',
    value: 'meetingKeyIds',
    type: 'select',
    data: [],
  },
  {
    name: '召开时间',
    value: 'startEndDate',
    type: 'dateRange'
  },
  {
    name: '状态',
    value: 'status',
    type: 'select',
    data: [
      {
        value: '20',
        label: '待开始'
      },
      {
        value: '30',
        label: '进行中'
      },
      // {
      //   value: '35',
      //   label: '审批中'
      // },
      {
        value: '40',
        label: '已完结'
      }
    ]
  }
]
export default {
  name: 'a' + Date.now(),
  components: {
    STable,
    listStatus
  },
  data() {
    this.columns = columns
    return {
      queryParam: {},
      loadData: async (parameter) => {
        this.queryParam.query = { ...this.queryParam.query, typeId: 6 }
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        const [err, res] = await getMeetingList(requestParameters)
        return new Promise((resolve, reject) => {
          if (err) {
            reject(err)
          } else {
            resolve(res)
          }
        })
      },
      searchArr: searchArr
    }
  },
  created() {
    this.getmeetType()
  },
  mounted() {
  },
  methods: {
    getmeetType() {
      meetingTypeApi.list({}, { pageNo: 1, pageSize: 1000, query: { type: 12, enable: true } }).then((res) => {
        if (res.code === this.SUCCESS_CODE) {
          let data = res.data.map(v => {
            v.disabled = v.enabled !== 'TRUE'
            v.value = v.id
            v.label = v.name
            return v
          })
          this.searchArr.find(item => item.value === 'meetingKeyIds').data = data
        }
    })
    },
    look(record) {
      let pageType
      if (record.status === 20) pageType = 'start'
      if (record.status === 30) pageType = 'edit'
      if (record.status === 35 || record.status === 40) pageType = 'look'
      this.$router.push({
        name: 'safetyMeetingInputSummary',
        query: { id: record.id || '', pageType }
      })
    },
    edit(record, type) {
      this.$router.push({
        name: 'safetyMeetingAddConference',
        query: {
          id: type === 2 ? record.id : '',
          pageType: type === 2 ? 'edit' : 'add',
          typeId: 6
        }
      })
    },
    //搜索
    search(val = {}) {
      this.queryParam.query = {
        ...val,
        typeId: 6,
        meetingKeyIds: val.meetingKeyIds ? [val.meetingKeyIds] : [],
        hsemonth: (val.month && val.month.format('YYYY-MM')) || void 0,
        startTime:
          (val.startEndDate && val.startEndDate.length && val.startEndDate[0].format('YYYY-MM-DD')) || void 0,
        endTime:
          (val.startEndDate && val.startEndDate.length && val.startEndDate[1].format('YYYY-MM-DD')) || void 0
      }
      console.log(this.queryParam)

      this.$refs.table.refresh(true)
    },

    // 处理更新操作（新增、编辑）
    async handleUpdate(type, data = {}) {
      if (type == 'del') {
        this.$submitConfirm(async () => {
          const [err, res] = await deleteById({ id: data.id })
          if (!err) {
            this.$message.success('删除成功')
            this.$refs.table.refresh(true)
          }
        }, '确认删除？')
      } else if (type == 'look' || type == 'start') {
        this.$router.push({
          name: 'safetyMeetingInputSummary',
          query: {
            id: data.id || '',
            pageType: type
          }
        })
      } else {
        this.$router.push({
          name: 'safetyMeetingAddConference',
          query: {
            id: data.id || '',
            pageType: type,
            typeId: 6
          }
        })
      }
    }
  }
}
</script>
